<?php

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty plugin
 *
 * Type modifier
 * package App
 * Purpose 
 * 文字数でカットする 
 *
 *
 * Example:  {$string|mb_truncate}
 * @version  1.0
 * @author   $Author: moriwaki $
 * @version $Id: 2008-09-18 moriwaki $
 * @return string
 */

function smarty_modifier_mb_truncate($string, $length = 80, $etc = '..', $encode="utf8")
{
    $string_len = mb_strlen($string);
    if ($string_len > $length) {
        $etc_len = mb_strlen($etc);
        $tmp_len = $length - $etc_len;
        $string = mb_strcut($string, 0, $tmp_len);
    }
    return $string;
}
